package com.ybkj.o2o.zhuanche.amqp;

import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfiguration {

  public static final String EXCHANGE_NAME = "xiaoka.push.exchange";

  public static final String DS_EXCHANGE_NAME = "xiaoka.dockingSupervise.xm.exchange";

  @Autowired
  private ConnectionFactory connectionFactory;

  @Bean
  public FanoutExchange shopExchange() {
    return new FanoutExchange(EXCHANGE_NAME, true, false);
  }
  /**
   * 消息服务器名称.
   * @return 消息队列对象
   */
  
  @Bean
  public RabbitTemplate shopRabbitTemplate() {
    RabbitTemplate template = new RabbitTemplate(connectionFactory);
    template.setExchange(EXCHANGE_NAME);
    Jackson2JsonMessageConverter jackson2JsonMessageConverter = new Jackson2JsonMessageConverter();
    jackson2JsonMessageConverter.setDefaultCharset("UTF-8");
    template.setMessageConverter(jackson2JsonMessageConverter);
    return template;
  }

  @Bean
  public RabbitTemplate dsRabbitTemplate() {
    RabbitTemplate template = new RabbitTemplate(connectionFactory);
    template.setExchange(DS_EXCHANGE_NAME);
    template.setMessageConverter(new Jackson2JsonMessageConverter());
    return template;
  }
}
